package com.example.demo.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @Author
 * @Description
 */
@Component
public class RequestInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String host = request.getHeader("host");
        System.err.println(host);
        if (Objects.equals(host, "localhost")){
            return true;
        } else {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);

            return false;
        }
    }
}
